﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace mebc4.tablebased
{
    [TestFixture]
    public class test_Runtime_helpers
    {
        public class Has_static_methods
        {
            public static void PublicStaticProc() {}
            public static int PublicStaticFunc() { return 0; }

            public void PublicProc() {}

            internal static void InternalStaticProc() {}
        }

        public class Has_instance_methods
        {
            public void PublicProc() { }
            public int PublicFunc() { return 0; }

            public static void PublicStaticProc() { }

            internal void InternalProc() { }
        }


        [Test]
        public void Find_static_methods()
        {
            var methods = MebcRuntime.FindStaticMethods(typeof(Has_static_methods));
            Assert.That(methods.Select(mi => mi.Name), Is.EquivalentTo(new[] {"PublicStaticProc", "PublicStaticFunc"}));
        }

        [Test]
        public void Find_instance_methods()
        {
            var methods = MebcRuntime.FindInstanceMethods(new Has_instance_methods());
            Assert.That(methods.Select(mi => mi.Name).ToArray(), Is.EquivalentTo(new[] { "PublicProc", "PublicFunc" }));
        }

        [Test]
        public void Is_function()
        {
            var mi = typeof (Has_static_methods).GetMethod("PublicStaticProc");
            Assert.IsFalse(MebcRuntime.IsFunction(mi));
            mi = typeof(Has_static_methods).GetMethod("PublicStaticFunc");
            Assert.IsTrue(MebcRuntime.IsFunction(mi));
        }

        [Test]
        public void Build_output_action()
        {
            var sut = new MebcRuntime();
            var d = sut.BuildOutputAction(typeof(int), "x");
        }
    }
}